package com.universe.test;

import java.util.ArrayList;
import java.util.List;

import javax.measure.quantity.Duration;
import javax.measure.quantity.Length;
import javax.measure.unit.SI;

import org.jscience.physics.amount.Amount;

import com.universe.objects.Body;

public class Universe {
	
	private List<Body> bodies;
	private Amount<Length> size;
	
	public Universe(Amount<Length> size, Body... bodies){
		this.size = size.to(SI.METER);
		this.bodies = new ArrayList<>();
		
		for(Body b: bodies){
			this.bodies.add(b);
		}
	}
	
	public Amount<Length> getSize(){
		return this.size;
	}
	
	public List<Body> getBodies(){
		return this.bodies;
	}
	
	public void iterate(){
		Amount<Duration> dT = Amount.valueOf(2000,SI.SECOND);
		for(Body b: bodies){
			b.zeroAcc();
		}
		for(int i=0; i<bodies.size(); i++){
			for(int j=0; j<bodies.size(); j++){
				if(i != j){
					bodies.get(i).gainBodyInfluence(bodies.get(j));
				}
			}
		}
		for(Body b: bodies){
			b.move(dT);
		}
	}
	
}
